package com.dstation.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dstation.dao.CollectionInfoMapper;
import com.dstation.domain.CollectionInfo;
import com.dstation.domain.VideoInfo;
import com.dstation.service.interf.ICollectVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Timestamp;
/**
 * @author:  Jeadon
 * @create:  2022/4/7 15:50
 * @tip:  收藏类Service层
 * @param:
 *
 **/
@Service
public class CollectVideoServiceImpl  implements ICollectVideoService  {

    @Resource
    private CollectionInfoMapper collectionInfoMapper;


    @Override
    public boolean memoryCollections(Long userId,Long videoId) {

        Timestamp time = new Timestamp(System.currentTimeMillis());

        return collectionInfoMapper.insertCollection(userId,videoId,time)==1;
    }

    @Override
    public boolean cancelCollections(Long userId, Long videoId) {

        return collectionInfoMapper.deleteCollection(userId,videoId)==1;
    }

    @Override
    public IPage<VideoInfo> findCollections(Page<VideoInfo> collectionInfoPage, Long userId) {

        return collectionInfoMapper.selectCollections(collectionInfoPage,userId);
    }

    @Override
    public boolean findHaveCollection(Long userId, Long videoId) {
        return collectionInfoMapper.selectHaveCollection(userId,videoId).size()==1;
    }
}
